const app = require("express").Router();
const multer = require("multer");
const { uploadOne } = require("../utils/s3/upload");
const { searchPlace } = require("../service/third/map");

const upload = multer({
  dest: "upload/",
  limits: {
    fileSize: 2 * Math.pow(1024, 2),
  },
});

app.post("/auth/upload", upload.single("file"), async (req, res) => {
  const data = await uploadOne(req.file, {
    path_name: `ice-user/${req.user.id}-${new Date().format(
      "yymmdd-HHiiss"
    )}.jpg`,
    ...req.body,
  });
  res.send(data);
});

app.get("/auth/map/search-place", async (req, res) => {
  const data = await searchPlace(req.query);
  res.send(data);
});

module.exports = app;
